package com.fs.system.college_admin.service;

import com.fs.system.college_admin.domain.Classes;
import com.fs.system.college_admin.domain.Grade;
import com.fs.system.college_admin.domain.Speciality;
import com.fs.system.college_admin.mapper.CollegeAdminGradeMapper;
import com.fs.system.common.ResponseData;
import com.fs.system.exception.CustomerException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@Service
public class CollegeAdminGradeService {
    @Autowired
    private CollegeAdminGradeMapper collegeAdminGradeMapper;

    public PageInfo<Grade> getGrade(Grade grade, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Grade> gradeList = collegeAdminGradeMapper.selectAll(grade);
        return PageInfo.of(gradeList);
    }

    public List<Grade> getAllGrade(Grade grade) {
        return collegeAdminGradeMapper.selectAll(grade);
    }

    public void addGrade(Grade grade) {
        //首先判断是否存在
        Grade dbgrade = collegeAdminGradeMapper.selectByGrade(grade.getYear());
        if(!Objects.isNull(dbgrade)){
            throw new CustomerException("500","添加不合法");
        }
        grade.setCreateTime(LocalDateTime.now());
        grade.setStatus("0");
        grade.setDeleted(false);
        collegeAdminGradeMapper.addGrade(grade);
    }


    /**
     * 修改年级的状态
     * @param grade
     */
    public void modifyGrade(Grade grade) {
        //首先判断是否存在
        Grade dbgrade = collegeAdminGradeMapper.selectByGrade(grade.getYear());
        if(Objects.isNull(dbgrade)){
            throw new CustomerException("500","修改不合法");
        }
        grade.setUpdateTime(LocalDateTime.now());
        collegeAdminGradeMapper.updateGrade(grade);
    }
}
